

System.Gadget.onSettingsClosing = settingsClosing;
 
function readSetting( settingName, defaultValue )
{
	var val = System.Gadget.Settings.read( settingName );
	if ( val != "" ) 
	{
		return val;
	}
	return defaultValue;
} 
 
function CheckAndSet( variablename ) 
{
	var varEl = document.getElementById( variablename );
	var varVal = varEl.value;
	System.Gadget.Settings.write( variablename, varVal );
}
 
function loadSettings()
{
	url.value = readSetting("url", "192.168.2.80:9091");
	username.value = readSetting("username", "admin");
	password.value = readSetting("password", "admin"); 
	refresh.value = readSetting("refresh", 1000);
}
 	
function settingsClosing(event)
{
	if (event.closeAction == event.Action.commit)
	{ 
		CheckAndSet("url");
		CheckAndSet("username");
		CheckAndSet("password");
		CheckAndSet("Refresh");
	}
 }